package br.com.dex.dexfitness.activitys;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import br.com.dex.dexfitness.R;

public class NovoAlunoActivity extends Activity implements OnClickListener {

	private static final int REQUEST_IMAGE_CAPTURE = 1;
	private ImageView cancelarCadastro;
	private ImageView capturarFoto;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_novo_aluno);
		cancelarCadastro = (ImageView)findViewById(R.id.btn_fechar_cadastro);
		capturarFoto = (ImageView)findViewById(R.id.btn_tirar_foto);
		cancelarCadastro.setOnClickListener(this);
		capturarFoto.setOnClickListener(this);
	}
	
	@Override
	public void onClick(View view) {
		// TODO Auto-generated method stub
		switch(view.getId())
		{
			case R.id.btn_fechar_cadastro:
				 Intent intent = new Intent(NovoAlunoActivity.this, MainActivity.class);
				 startActivity(intent);
				 finish();
				 break;
			case R.id.btn_tirar_foto:
				Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
				startActivityForResult(takePicture, REQUEST_IMAGE_CAPTURE);
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		
		if(requestCode==REQUEST_IMAGE_CAPTURE && resultCode==RESULT_OK){
			Bitmap bitmap = (Bitmap) data.getExtras().get("data");
			capturarFoto.setImageBitmap(bitmap);
		}
		
	}
}
